<template>
  <div>
    <el-dialog
      title="请选择"
      :close-on-click-modal="false"
      destroy-on-close
      :visible.sync="dialogVisible"
      width="25%"
      :before-close="close"
    >
      <el-form :model="infoModel" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="仓库：" prop="tagType">
          <el-radio-group v-model="infoModel.tagType">
            <el-radio :label="1">待审核</el-radio>
            <el-radio :label="2">通过审核</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="toExamineHandler">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'dialogModal',

  props: {
    showModal: {
      type: Boolean,
      default: false,
    },
  },

  watch: {
    showModal: {
      handler(val) {
        this.infoModel = {}
        this.dialogVisible = val
      },
      deep: true,
    },
  },

  data() {
    return {
      infoModel: {},
      rules: {
        tagType: [
          {
            required: true,
            trigger: 'change',
            message: '请选择',
          },
        ],
      },
      dialogVisible: this.showModal,
    }
  },

  methods: {
    toExamineHandler() {
      this.$refs.ruleForm.validate(async valid => {
        if (valid) {
          this.$emit('success', this.infoModel.tagType)
        }
      })
    },

    close() {
      this.dialogVisible = false
      this.$emit('close')
    },
  },
}
</script>
